package com.leo.offer;

/**
 * 斐波那契数列==青蛙跳台阶问题==1*2的矩形去覆盖2*n的矩形
 * @author xuexiaolei
 * @version 2018年03月01日
 */
public class T09 {
    public int f(int n){
        if (n < 2){ return n;}
        return f(n-1)+f(n-2);
    }

    public static int f2(int n){
        if (n < 2){ return n;}
        int n0 = 0, n1 = 1, temp=0;
        for (int i = 2; i <= n; i++) {
            temp = n0+n1;
            if (i%2==0){
                n0=temp;
            }else {
                n1=temp;
            }
        }
        return temp;
    }

    public static void main(String[] args) {
        System.out.println(f2(0));
        System.out.println(f2(1));
        System.out.println(f2(2));
        System.out.println(f2(3));
        System.out.println(f2(4));
        System.out.println(f2(5));
    }
}
